package zozopo.background.operator;

import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;


import zozopo.background.operator.operations.LimitedOS;
import zozopo.background.operator.operations.LimitedTB;
import zozopo.background.operator.operations.OperatorOS;
import zozopo.background.operator.operations.OperatorTB;
import zozopo.background.operator.operations.OperatorlimitedOS;
import zozopo.background.operator.operations.OperatorlimitedTB;
import zozopo.database.BusiDatabaseManager;
import zozopo.database.DatabaseManager;
import zozopo.user.operations.UserOS;
import zozopo.user.operations.UserTB;
import zozopo.warehouse.operations.GoodsOS;
import zozopo.warehouse.operations.GoodsTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class SelectOperatorlimitedAction extends ActionSupport implements Action,SessionAware{
	//传入参数
	private String limitedCode = "";
	//分页参数
	private int beginPageNum = 0;
	private int pageSize = 20;
	private int rowNum = 0;
	//传出参数
	private List<OperatorlimitedTB> operatorlimitedList;
	private LimitedTB limited;
	
	private Map<String,OperatorTB> operatorInfoMap;
	
	private Map<Object, Object> session;
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	public String execute(){
		
		
		
	
		
		DatabaseManager databaseManager = new BusiDatabaseManager();
		Connection conn = databaseManager.getConnection();
		
		OperatorOS operatorOS = new OperatorOS(conn);
		OperatorlimitedOS operatorlimitedOS = new OperatorlimitedOS(conn);
		LimitedOS limitedOS = new LimitedOS(conn);
		
		Map<String,LimitedTB> limitedMap = limitedOS.selectMap();
		
		if(limitedCode.equals("")){
			
			//userlimitedList = userlimitedOS.selectByLimitedcode(limitedCode);
			//rowNum = userlimitedOS.getRowNumForLimitedcode(limitedCode);
		}else{
			limited = limitedOS.getLimitedByCode(limitedCode);
			operatorlimitedList = operatorlimitedOS.selectByLimitedcode(limitedCode,beginPageNum, pageSize);

			rowNum = operatorlimitedOS.getRowNumForLimitedcode(limitedCode);
			
			operatorInfoMap = operatorOS.getOperatorInfoMap(operatorlimitedList);
		}
		
		
		databaseManager.releaseConnection(conn);
		
		return SUCCESS;

	}
	
	public void validate() {
		//权限处理
		//UserTB user = (UserTB) session.get("userInfo");
		
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 

		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		
		//用户权限
		//Map<String,OperatorlimitedTB> userlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
		
		//if(userlimitedMap.get(limitedCode) == null){
		//	addFieldError("errormessage","用户没有添加售后信息权限.");
		//	return;
		//}
		
	}
	
	
	public int getBeginPageNum() {
		return beginPageNum;
	}
	public void setBeginPageNum(int beginPageNum) {
		this.beginPageNum = beginPageNum;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getRowNum() {
		return rowNum;
	}
	public void setRowNum(int rowNum) {
		this.rowNum = rowNum;
	}
	public String getLimitedCode() {
		return limitedCode;
	}
	public void setLimitedCode(String limitedCode) {
		this.limitedCode = limitedCode;
	}
	
	public LimitedTB getLimited() {
		return limited;
	}
	public void setLimited(LimitedTB limited) {
		this.limited = limited;
	}
	public List<OperatorlimitedTB> getOperatorlimitedList() {
		return operatorlimitedList;
	}
	public void setOperatorlimitedList(List<OperatorlimitedTB> operatorlimitedList) {
		this.operatorlimitedList = operatorlimitedList;
	}
	public Map<String, OperatorTB> getOperatorInfoMap() {
		return operatorInfoMap;
	}
	public void setOperatorInfoMap(Map<String, OperatorTB> operatorInfoMap) {
		this.operatorInfoMap = operatorInfoMap;
	}
	

}
